

function clear(options){
	$.each(options,function(k,v){
		if(v=="text" || v=="hidden"){
			$("#"+k).val("");
		}
		if(v=="datebox" || v=="datetimebox"){
			$("#"+k).combo("clear");
		}
		if(v=="combobox"){
			$("#"+k).combobox("select","");
		}
	});
}/** * jquery ajaxComplete：onComplete全局事件  * @author zhangjie *///$(document).ajaxComplete(onComplete);function onComplete(event, xhr, settings) {	/* 用户会话失效或为登录，重定向至登录页面 */	if(settings.url=="login.jsp") {		window.location.replace(ctxPaths + "/login.jsp");	}}function compareDate(startDateStr,endDateStr) {	startDateStr=startDateStr.split('-');   	endDateStr=endDateStr.split('-');		var from =new Date();	from.setUTCFullYear(startDateStr[0], startDateStr[1] - 1, startDateStr[2]); 	from.setUTCHours(0, 0, 0, 0); 		var to = new Date();	to.setUTCFullYear(endDateStr[0], endDateStr[1] - 1, endDateStr[2]); 	to.setUTCHours(0, 0, 0, 0); 		if(from > to){		return false;	}	return true;}//比较时间 格式 yyyy-mm-dd hh:mi function comptime(beginTime,endTime){        var start=new Date(beginTime.replace("-", "/").replace("-", "/"));       var end=new Date(endTime.replace("-", "/").replace("-", "/"));      if(end<start){          return false;      }      return true;  }

function bizAdd(title) {
	if ($('#addIframe').attr('src')) {
		//$('#addIframe')[0].src = window.addPage;
		$("#addIframe")[0].contentWindow.bizReset();
		$('#addDialog').dialog('open'); 
		$("#addIframe").contents().find("body").scrollTop(0); 
	}else {
		$('#addIframe')[0].src = window.addPage;
		$('#addDialog').dialog({   
			modal:true ,
			title:"新增"+(title!=""?title:""),
			resizable : false
		}); 
		$('#addDialog').dialog('open'); 
	}
}

function bizUpdate(bizId,title) {
	if ($('#updateIframe').attr('src')) {
		$("#updateIframe")[0].contentWindow.init(bizId); 
		$('#updateDialog').dialog('open'); 
		$("#updateIframe").contents().find("body").scrollTop(0); 
	}else {
		$('#updateIframe')[0].src = window.updatePage+"?bizId= "+bizId;
		$('#updateDialog').dialog({   
			modal:true ,
			title:"修改"+(title||''),
			resizable : false
		}); 
		$('#updateDialog').dialog('open'); 
	}
}
function bizView(bizId,title) {
	if ($('#viewIframe').attr('src')) {
		$("#viewIframe")[0].contentWindow.init(bizId); 
		$('#viewDialog').dialog('open'); 
		$("#viewIframe").contents().find("body").scrollTop(0); 
	}else {
		$('#viewIframe')[0].src = window.viewPage+"?optType=view&bizId= "+bizId;
		$('#viewDialog').dialog({   
			modal:true ,
			title:(title||'')+"详情",
			resizable : false
		}); 
		$('#viewDialog').dialog('open'); 
	}
}

function bizFind(parm) {
	loadStar();
	jQuery.ajax( {
		url : window.findAction,
		type : "POST",
		cache : false,
		async : false,
		dataType : "json",
		data : parm,
		success : function(json, textStatus) {
			setParm(json); 
		},
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			setMessage(json.success);
		}
	});
	
	loadEnd();
}


function bizSave(bizId) {
	loadStar();
	bizId = bizId || $.trim($.query.get('bizId')); 
	var type = $.trim($.query.get('type')); 
	$("#frm").form("submit",{
		onSubmit:function(){
			if(!bizValidate()){
				return false;
			}
			var url;
			
			if(bizId!='' && type!='add'){
				url=window.updateAction;
			}else{
				url=window.addAction;
			}

			if($(this).form('validate')){
				jQuery.ajax( {
					url : url,
					type : "POST",
					cache : false,
					async : false,
					dataType : "json",
					data : $('#frm').serializeObject(),
					success : function(json, textStatus) {
						if(json.success==true){
							closeDialog();
							//window.parent.$('#datas').datagrid('reload');
							window.parent.$('#datas').datagrid({onLoadSuccess : function(data){							
								window.parent.$('#datas').datagrid('selectRecord',bizId);	
							}});
							setMessage(true);
						}else{
							$.messager.alert('提示消息', json.msg, 'warning');
						}
					},
					error : function(XMLHttpRequest, textStatus, errorThrown) {
						setMessage(false);
					}
				});
			}
			return false;
		}

	});
	
	loadEnd();
}$(document).ready(function() {
	/*window.ctx=getContextPath();	$(".easyui-combobox").each(function(){		var dictCode=$(this).attr("dictCode");		if(dictCode){			$(this).combobox({				url : window.ctx + '/common/dict/controller/dict/listDict.json?dictCode='+dictCode,				valueField : 'code',				textField : 'name'			});		}	});
	
	$(".easyui-combotree").each(function(){
		var dictCode=$(this).attr("dictCode");
		if(dictCode){
			$(this).combotree({
				url : window.ctx + '/common/dict/controller/dict/treeAllDict.json?dictCode='+dictCode,
				onBeforeSelect: function(node) {            
					if (!$(this).tree('isLeaf', node.target)) { 
						return false;
					}        
				}
			});
		}
	});*/});

function createFrame(url,width,height) {
	if($.support.msie){
		return '<iframe scrolling="auto" frameborder="0"  src="'+url+'" style="width:'+width+';height:'+height+';position:relative;"></iframe>';  
	}else{
		return '<iframe scrolling="auto" frameborder="0"  src="'+url+'" style="width:'+width+';height:'+height+';"></iframe>';  
	}
}


//检查是否安装了Adobe Reader
function isAcrobatPluginInstall() {
	var flag = false;
	var isIE =navigator.userAgent.toLowerCase().search(/(msie\s|trident.*rv:)([\w.]+)/)!=-1;
	// 如果是firefox浏览器
	// 下面代码都是处理IE浏览器的情况
	if (window.ActiveXObject || "ActiveXObject" in window) {
		for (x = 2; x < 10; x++) {
			try {
				oAcro = eval("new ActiveXObject('PDF.PdfCtrl." + x + "');");
				if (oAcro) {
					flag = true;
				}
			} catch (e) {
				flag = false;
			}
		}
		try {
			oAcro4 = new ActiveXObject('PDF.PdfCtrl.1');
			if (oAcro4)
				flag = true;
		} catch (e) {
			flag = false;
		}
		try {
			oAcro7 = new ActiveXObject('AcroPDF.PDF.1');
			if (oAcro7)
				flag = true;
		} catch (e) {
			flag = false;
		}
	}
	else if (navigator.plugins && navigator.plugins.length) {
		for (x = 0; x < navigator.plugins.length; x++) {
			if (navigator.plugins[x].name == 'Adobe Acrobat')
				flag = true;
		}
	}
	
	if (flag) {
		return true;
	} else {
		$.messager.confirm('提示消息','对不起,您还没有安装PDF阅读器软件呢,为了方便预览PDF文档,请选择安装！',function(flag){    
		    if (flag){    
		    	location = 'http://ardownload.adobe.com/pub/adobe/reader/win/9.x/9.3/chs/AdbeRdr930_zh_CN.exe';
		    }    
		}); 
	}
	return flag;
}

function getContextPath() {
    var pathName = document.location.pathname;
    var index = pathName.substr(1).indexOf("/");
    var result = pathName.substr(0,index+1);
    return result;
}

function textTrim(str) {  
    return str.replace(/\s+/g,"");  
}
